#pragma once

#include "task.hxx"
#include "utility.hxx"

#include <map>

class User;
class FileLog;

class EXPORT YKTask : public Task
{
public:
	YKTask(FileLog* filelog = NULL);
	YKTask(const User* user, int id, const string& taskInfo, TaskStatus status = LOADED, FileLog* filelog = 0);
	YKTask(const YKTask& model);
	
	virtual void Execute(void);

	virtual Task::ActionType NextAction();
	virtual Task::ActionResult RefreshCaptcha(void);
	virtual Task::ActionResult Query(void);
	virtual Task::ActionResult PickResult(void);
	virtual Task::ActionResult Refresh(void);

	virtual bool IsCaptchaed(void) const;
	virtual bool SetCaptcha(const string& val);

	Task::ActionResult Login(void);
	Task::ActionResult ChangePwd(void);
	Task::ActionResult Confirm(void);

	virtual string Signature(void) const;
	virtual bool AdjustStatus(void);

	virtual bool Update(void);

	std::map<std::string, std::string> GetKdmcs(void) const;

	PROPERTY_TASKINFO(xypwd);
	PROPERTY_TASKINFO(nxypwd);
	PROPERTY_TASKINFO(jx);
	PROPERTY_TASKINFO(kmmc);
	PROPERTY_TASKINFO(kscx);
	PROPERTY_TASKINFO(kdmc);
	PROPERTY_TASKINFO(kdmcs);
	PROPERTY_TASKINFO(ykrq);
	PROPERTY_TASKINFO(ykday);
	PROPERTY_TASKINFO(yyrs);
	PROPERTY_TASKINFO(ksxz);

	PROPERTY(SpawnCounter, int);

private:
	mutable Mutex stateInUse;
	int sequence;
	string kdmcCode;

	//////////////////////////////////////////////
	// extracted from page
	std::map<std::string, std::string> LatestKdmcs;
};